﻿using MenuService.Public;
using StudentsPrenseLog.Services;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudentsPrenseLog
{
    public class Application
    {
        private StudentService _studentsService;

        public Application()
        {
            _studentsService 
                = new StudentService(
                    new Repositories.StudentRepository(
                        ConfigurationManager.AppSettings["FilePath"] ?? "storage.txt",
                        ConfigurationManager.AppSettings["DateFormat"] ?? @"dd\MM\yyyy",
                        ConfigurationManager.AppSettings["FileDelimeter"] ?? "\x0005"));
            
        }

        public void Exit()
        {
            Environment.Exit(0);
        }

        public void Start()
        {
            MenuControlFacade menu = new MenuControlFacade("Menu.txt");
            menu.BindMethod("4", Exit);
            menu.BindMethod("1.1",   _studentsService.CreateStudent);
            menu.BindMethod("1.4",   _studentsService.FindStudents);
            menu.BindMethod("1.3.2", _studentsService.DeleteStudents);
            menu.BindMethod("1.2", _studentsService.UpdateStudent);
            menu.PrintMenu2Console();
            menu.StartInputListening();
        }
    }
}
